﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using SMS.DAL;
using SMS.Entities.Admin;
using SMS.Entities;

namespace SMS.Web.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "AuthenticationService" in code, svc and config file together.
    public class AuthenticationService : IAuthenticationService
    {
        public void DoWork()
        {

        }

        public Entities.Admin.ApplicationUser AuthenticateUser(string userName, string password, bool isLoggedIn, out Entities.SMSException serviceError)
        {
            try
            {
                serviceError = null;
                return new AuthenticationDA().AuthenticateUser(userName, password, isLoggedIn);
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return null;
            }

        }

        public int ResetPassword(string username, string currentPassword, string newPassword)
        {
            try
            {
                
               return new AuthenticationDA().ResetPassword(username, currentPassword, newPassword);
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public ApplicationUser SaveNewUser(string username, ApplicationUser applicationUserObject, out SMSException serviceError)
        {
            try
            {
                serviceError = null;
                return new SMS.DAL.AuthenticationDA().SaveObject(username, applicationUserObject);
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return null;
            }
        }

        public List<ApplicationUser> GetApplicationUserList(string UserName, string SearchText, out SMSException serverError)
        {
            try
            {
                serverError = null;
                return new SMS.DAL.AuthenticationDA().SearchObject(UserName, SearchText).ToList();
            }
            catch (Exception ex)
            {
                serverError = new Entities.SMSException(ex);
                return null;
            }
        }

        public int AdminResetPassword(string username,  string newPassword)
        {
            try
            {
                return new AuthenticationDA().AdminResetPassword(username,  newPassword);
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public SMS.Entities.Master.Branch GetBranchDetail(int branch_ID,out SMSException serverError)
        {
            try
            {
                serverError = null;
                return new SMS.DAL.AuthenticationDA().SelectBranchDetail(branch_ID);
            }
            catch (Exception ex)
            {
                serverError = new Entities.SMSException(ex);
                return null;
            }
        }

    }
}
